package com.nc.menu.dao;

import com.nc.menu.model.dto.MenuDto;
import com.nc.menu.model.entity.MenuEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
public interface MenuDao extends JpaRepository<MenuEntity, String> {
    @Query(value = "SELECT b.* FROM menu_entity as b " +
            "left join menu_permissions_entity as c " +
            "on b.id = c.menu_id where c.permission in (?1)",
            nativeQuery = true)
    List<MenuEntity> findByPermissions(List<String> pers);

    @Query(value = "SELECT b.* FROM menu_entity as b " +
            " left join menu_permissions_entity as c " +
            " on b.id = c.menu_id where c.permission in (select d.code from frm_users as a LEFT JOIN frm_users_frm_roles as b on a.id = b.frm_users_id" +
            " LEFT JOIN frm_role_permissions_role as c on b.frm_roles_id = c.frm_role_id" +
            " LEFT JOIN frm_permissions as d on d.id = c.permissions_role_id where a.id = ?2 GROUP BY d.code) and b.status = ?1",
            nativeQuery = true)
    List<MenuEntity> findByStatusAndUserId(Boolean status, String pers);
}
